#include "main.h"

Polygon r;
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    // glutInitWindowPosition(770, 400);
    glutCreateWindow(PROGRAM_NAME);
    glutDisplayFunc(&onRenderScene);
    // glutIdleFunc(idle);
    inital();
    glutMainLoop();
    return 0;
}

void onRenderScene(void)
{
    // 使用当前颜色清空缓冲区,即设定背景颜色
    glClear(GL_COLOR_BUFFER_BIT);
    // 设定画笔颜色
    // glColor3f(1, 0, 0);
    glColor3f(76.0 / 255, 180.0 / 255, 231.0 / 255);
    printf("%d,%d\n", r.points.front().x, r.points.front().y);
    Lines ls = r.getEdges();
    for (Lines::iterator iter = ls.begin(); iter != ls.end(); ++iter)
    {
        iter->draw();
    }
    glFlush();
}

void inital()
{
    // 定义窗体尺寸
    windowWidth = WINDOW_SIZE;
    windowHeight = WINDOW_SIZE;
    gluOrtho2D(0, windowWidth, 0, windowHeight);

    glClearColor(1, 1, 1, 1);

    r.addPoint({100, 100});
    r.addPoint({170, 260});
    r.addPoint({240, 120});
    r.addPoint({170, 180});

    Line<ValueType> a({0,0},{20,20}),b({0,10},{20,0});
    Point<ValueType>* c = a.crossWith(b);
    if (c)
    {
    printf(("cross @ (%d,%d)"),c->x,c->y);
        
    }
}
void idle(void) //空闲函数
{
    glutPostRedisplay();
}